#include <clusnet/net/TcpServer.h>
#include <iostream>

int main(int argc, char* argv[])
{
    InitLogging("PingPongServer", ".");
    try
    {
        if (argc < 4)
        {
            LOG(ERROR) << "Usage: TcpServer_test <port> <thread_num> <io_num>";
            return 1;
        }

        clusnet::net::TcpServer server(boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), std::atoi(argv[1])));
        server.setMessageCallback([](clusnet::net::TcpConnectionPtr& conn, clusnet::net::TcpUniqDataPacketPtr&& data)
        {
            conn->safeAsyncWrite(std::move(data));
        });
        server.start(std::atoi(argv[2]), std::atoi(argv[3]));

        std::mutex  mu;
        std::unique_lock<std::mutex>    lock(mu);
        std::condition_variable quit;
        quit.wait(lock, [] { return false; });
        LOG(INFO) << "stop server";
        server.stop();
    }
    catch (std::exception& e)
    {
        LOG(ERROR) << "Exception: " << e.what();
    }
    getchar();

    return 0;
}
